package com.lys.blog.controller;



import com.lys.blog.common.aop.Cache;
import com.lys.blog.common.aop.LogAnnotation;
import com.lys.blog.service.impl.ArticleServiceImpl;
import com.lys.blog.vo.Result;
import com.lys.blog.vo.params.ArticleParam;
import com.lys.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//JSON数据进行交互
@RestController
@RequestMapping("articles")
public class ArticleController {
    @Autowired
    private ArticleServiceImpl articleServiceImpl;

    @PostMapping
    @LogAnnotation(module = "文章",operation = "获取文章列表")
    @Cache(expire = 5 * 60 * 1000,name = "listArticle")
    public Result listArticle(@RequestBody PageParams pageParams) {
        return articleServiceImpl.listArticle(pageParams);
    }

    /**
     * 首页最热文章
     * @return
     */
    @PostMapping("hot")
    @LogAnnotation(module = "文章",operation = "获取最热文章列表")
    @Cache(expire = 5 * 60 * 1000,name = "hot_article")
    public Result hotArticle() {
        int limit = 5;
        return articleServiceImpl.hotArticle(limit);
    }


    /**
     * 首页显示最新文章
     */
    @PostMapping("new")
    @LogAnnotation(module = "模块名",operation = "操作")
    public Result newArticle() {
        int limit = 5;
        return articleServiceImpl.newArticle(limit);
    }

    /**
     * 文章归档
     */
    @PostMapping("listArchives")
    public Result listArchives() {
        return articleServiceImpl.listArchives();
    }

    @PostMapping("/view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId) {
        return articleServiceImpl.findArticleById(articleId);
    }

    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam) {
        return articleServiceImpl.publish(articleParam);
    }
}
